-
Notifications
You must be signed in to change notification settings - Fork 46.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist. #10385
Conversation
:O |
@@ -67,12 +60,23 @@ var HTMLDOMPropertyConfig = { | |||
// Style must be explicitely set in the attribute list. React components | |||
// expect a style object | |||
start: HAS_NUMERIC_VALUE, | |||
// Style must be explicitely set in the attribute list. React components |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: explicitly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
srcLang: 0, | ||
srcSet: 0, | ||
// Style must be explicitely set in the attribute list. React components | ||
// expect a style object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yikes! Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 3a50c07
How did you verify the changes? Is it worth creating a test page with all these attributes to ensure their support didn’t regress? (At least once.) |
My testing could be more exhaustive. I'll make a test page. |
label: 0, | ||
lang: 0, | ||
list: 0, | ||
loop: HAS_BOOLEAN_VALUE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anything special about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack! This is a mistake 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added back in a218130
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is still missing in the latest version here, unless I'm missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see it moved down.
srcSet: 0, | ||
start: HAS_NUMERIC_VALUE, | ||
step: 0, | ||
// Style must be explicitly set in the attribute list. React components |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a note about server renderer? I imagine we don't get into style
branch on the client because there’s a hardcoded one earlier.
What about custom elements? Does style
still work correctly on those? (And did it at all in the past?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent questions. I will verify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine we don't get into style branch on the client because there’s a hardcoded one earlier.
We don't get to the style branch, but we validate all properties here:
https://github.com/facebook/react/blob/master/src/renderers/dom/fiber/ReactDOMFiberComponent.js#L406
The UnknownPropertyHook calls DOMProperty.shouldSetAttribute
and sees that the style property is using an object, so it warns. This check doesn't happen if the style property is in the attribute config.
So keeping style: 0
here prevents the warning.
What about custom elements? Does style still work correctly on those? (And did it at all in the past?)
What is the intended behavior of passing style
to custom elements? Should it pass the value "as is", or provide style pre-processing? Right now it looks like it's sending down a style string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for now we're okay with doing whatever we used to be doing.
a218130
to
019de2b
Compare
@@ -66,7 +66,8 @@ var HTMLDOMPropertyConfig = { | |||
// See http://schema.org/docs/gs.html | |||
itemScope: HAS_BOOLEAN_VALUE, | |||
// Facebook internal attribute. This is an object attribute that | |||
// impliments a custom toString() method | |||
// impliments a custom toString() method. Objects are not allowed as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: implements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Man I need a git commit hook for impliments. Every. Single. Time. Fixed in aaafa7f
return DOMProperty.properties.hasOwnProperty(lowerCased) | ||
? DOMProperty.properties[lowerCased] | ||
: null; | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a final word here. In this scenario, all attributes are referenced as their lowercase form internally. I've hidden that within getPropertyInfo
to avoid needing to know about lowercasing attributes outside of DOMProperty.js
.
y2: 0, | ||
yChannelSelector: 'yChannelSelector', | ||
z: 0, | ||
zoomAndPan: 'zoomAndPan', | ||
}; | ||
|
||
var SVGDOMPropertyConfig = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like there's another step here where we could string manipulate xml:lang
or vert-origin-y
into camel-case, that might cut the overall gzip size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I want to try it. I'll take 5.
aaafa7f
to
d51ee9d
Compare
} | ||
|
||
if (DOMAttributeNamespaces.hasOwnProperty(propName)) { | ||
propertyInfo.attributeNamespace = DOMAttributeNamespaces[propName]; | ||
} | ||
|
||
if (DOMPropertyNames.hasOwnProperty(propName)) { | ||
propertyInfo.propertyName = DOMPropertyNames[propName]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DOMPropertyNames is not used by any injection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is amazing work.
There's a (hopefully!) last change in semantics we need to make that I wrote about in #10399 (comment).
Thanks again for working through this! I really hope this is the last change we need to make. If not, I’ll try to address the rest myself tomorrow.
additive: 0, | ||
alignmentBaseline: 'alignment-baseline', | ||
allowReorder: 'allowReorder', | ||
alphabetic: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't figure out if this is a boolean attribute or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just discovered this page. True life saver.
ascent: 0, | ||
attributeName: 'attributeName', | ||
attributeType: 'attributeType', | ||
autoReverse: 'autoReverse', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not in the spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh fun.
hanging: 0, | ||
horizAdvX: 'horiz-adv-x', | ||
horizOriginX: 'horiz-origin-x', | ||
ideographic: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a value for dominantBaseline
, and I can't find a description of it anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Number.
https://www.w3.org/TR/SVG/fonts.html#FontFaceElementIdeographicAttribute
Jeez Nate. Why don't you read the spec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha :-) It's a bit tough to find.
We'll really need some automated way to test we didn't regress here (just once). I'm thinking maybe we could take all existing whitelists, make a page that renders all these properties with React 15, and then verify these values are still there with 16. I'll try to do it tomorrow. |
@gaearon Okay. This is not in a fully tested, and possibly not in a working state, but I've pushed up commits that add back what I believe are all the boolean properties. In addition to the ones you identified, I went through the entire SVG spec (okay okay I cmd + f'ed through it) and the only boolean SVG attributes I could find were:
autoReverse is technically from SMIL. I'll browse through and see if we aren't missing anything. |
SMIL state module defines a few more:
I think that's it. |
Follow-up work from #7311. This PR implements scenario 2 for custom attributes, as described in #7311 (comment).
arabicform
, do not alias. They write asclassname
,htmlfor
, andarabicform
.Build size:
react-dom.production.min.js: 109.01kb (34.40kb gz)